package cn.slipi.admin.task;

import cn.slipi.admin.common.utils.DateUtil;
import cn.slipi.admin.common.utils.dozer.impl.ConvertBean;
import cn.slipi.admin.dao.PdrApiMapper;
import cn.slipi.admin.dao.TSysAdminLogMapper;
import cn.slipi.admin.entity.PdrApi;
import cn.slipi.admin.entity.PdrProject;
import cn.slipi.admin.entity.TSysAdminLog;
import cn.slipi.admin.service.dto.in.m.SysAdminLogDTO;
import cn.slipi.admin.service.dto.out.KeyUpdateInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TODO: 请添加描述
 *
 * @author lee
 * @date 2019/4/25
 * @since 1.0.0
 */
@Component
public class PdrApiTask {

    @Autowired
    private ConvertBean convertBean;

    @Autowired
    private PdrApiMapper pdrApiMapper;

    @Async
    public void update(Integer id, KeyUpdateInfo keyUpdateInfo) {
        List<PdrApi> pdrApiList = this.getPdrApiListByProjectId(id);
        pdrApiList.forEach(pdrApi -> {
            pdrApi.setKeyUpdateTime(DateUtil.getTimeByMinSecond());
            this.convertBean.convertNotNull(keyUpdateInfo, pdrApi, false, true);
            this.pdrApiMapper.updateById(pdrApi);
        });
    }

    private List<PdrApi> getPdrApiListByProjectId(Integer id) {
        QueryWrapper<PdrApi> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pdr_project_id", id);
        queryWrapper.eq("status", 1);
        return this.pdrApiMapper.selectList(queryWrapper);
    }


}
